﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - StudentManage</title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" />
    <link href="~/js/layui-v2.5.5/layui/css/layui.css" rel="stylesheet" />
    <link href="~/js/layui-v2.5.5/layui/css/modules/laydate/default/laydate.css" rel="stylesheet" />
    <link href="~/js/layui-v2.5.5/layui/css/modules/code.css" rel="stylesheet" />
</head>
<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin">
        <div class="layui-header">
            <div class="layui-logo">学生信息管理系统</div>

            <!-- 头部区域（可配合layui已有的水平导航） -->
            <ul class="layui-nav layui-layout-right" style="text-align: center;">
                <li class="layui-nav-item">
                    <a href="javascript:;">
                        <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
                        @ViewBag.RealName
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="/StudentManage/UserInfo/Index" data-ajax-update="#LAY_app_body" data-ajax="true" >基本资料</a></dd>
                        @*<dd><a href="">安全设置</a></dd>*@
                        <dd><a href="/Home/Logout">退出</a></dd>
                    </dl>
                </li>
            </ul>
        </div>

        <div class="layui-side layui-bg-black">
            <div class="layui-side-scroll">
                <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
                <ul class="layui-nav layui-nav-tree" lay-filter="module">
                </ul>
            </div>
        </div>

        <div class="layui-body" id="LAY_app_body">
            <!-- 内容主体区域 -->
            <div style="padding: 15px;">
                <main role="main" class="pb-3">
                    @RenderBody()
                </main>
            </div>
        </div>

        <div class="layui-footer">
            <!-- 底部固定区域 -->
            <div class="container" style="text-align:center">
                &copy; 2020 - StudentManage - <a asp-area="" asp-controller="Home" asp-action="Index">Privacy</a>
            </div>
        </div>
    </div>

    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="~/lib/microsoft.jquery.unobtrusive.ajax/3.2.6/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/js/site.js" asp-append-version="true"></script>
    <script src="~/js/layui-v2.5.5/layui/layui.js"></script>
    <script src="~/js/xm-select/dist/xm-select.js"></script>
    @RenderSection("Scripts", required: false)

    <script>

        layui.use(['layer', 'form', 'element'], function () {
            var $ = layui.$
                , layer = layui.layer
                , form = layui.form
                , element = layui.element;

            //获取所有的菜单
            $.ajax({
                type: "GET",
                url: "/StudentManage/Module/Modules?token=" + localStorage.token,
                dataType: "json",
                async: false,
                success: function (data) {
                    if (data.status !== "error") {
                        //先添加所有的主菜单
                        $.each(data.info, function (i, obj) {
                            var content = '<li class="layui-nav-item">';

                            content += '<a class="" href="javascript:">' + obj.name + '</a>';
                            //这里是添加所有的子菜单
                            content += loadChild(obj);
                            content += '</li>';
                            $(".layui-nav-tree").append(content);
                        });
                        //将Span元素置顶，不然会被覆盖
                        $(".layui-nav-bar").attr("class", "zorder:999;");
                        //重新渲染
                        element.render('nav', 'left-menu');
                        element.init();
                    }
                },
                error: function (jqXHR) {
                    alert("发生错误：" + jqXHR.status);
                }
            });

            //组装子菜单的方法
            function loadChild(obj) {
                var content = '';
                if (obj != null) {
                    if (obj.children.length > 0) {
                        content += '<dl class="layui-nav-child">';
                    } else {
                        content += '<dl>';
                    }
                    if (obj.children.length > 0) {
                        $.each(obj.children, function (i, child) {
                            content += '<dd>';
                            content += '<a href="' + child.url + '" data-ajax-update="#LAY_app_body" data-ajax="true" style="margin-left: 10px;">' + child.name + '</a>';
                            if (child.children.length === 0) {
                                return;
                            }
                            content += loadChild(child);
                            content += '</dd>';
                        });

                        content += '</dl>';
                    }
                    console.log(content);
                }
                return content;
            };
        });
    </script>

</body>
</html>
